import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/faceLoginPage',
    component: ()=> import('@/views/login/components/faceLoginPage'),
    name:'/faceLoginPage',
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '首页', icon: 'dashboard', affix: true }
      }
    ]
  }
]

/**
 * 全局的菜单
 */
export const asyncRoutes = [
  {
    path: '/village',
    component: Layout,
    redirect: '/village/floor',
    alwaysShow: true, // will always show the root menu
    name: '/village',
    meta: {
      title: '资产管理',
      icon: 'el-icon-coin'
    },
    children: [
      {
        path: 'floor',
        component: () => import('@/views/assets/floor'),
        name: '/village/floor',
        meta: {
          title: '楼栋管理',
          icon: 'el-icon-office-building'
        }
      },
      {
        path: 'unit',
        component: () => import('@/views/assets/unit'),
        name: '/village/unit',
        meta: {
          title: '单元管理',
          icon: 'el-icon-school'
        }
      },
      {
        path: 'house',
        component: () => import('@/views/assets/room'),
        name: '/village/house',
        meta: {
          title: '房屋管理',
          icon: 'el-icon-house'
        }
      },
      {
        path: 'addHouse',
        component: () => import('@/views/assets/room/addHouse/checkS'),
        name: '/village/addHouse',
        meta: {
          title: '添加房屋',
          icon: 'el-icon-house'
        }
      },
      {
        path: 'shops',
        component: () => import('@/views/error-page/404'),
        name: '/village/shops',
        meta: {
          title: '商铺管理',
          icon: 'el-icon-s-shop'
        }
      }
    ]
  },
  {
    path: '/owner',
    component: Layout,
    redirect: '/owner/master',
    name: '/owner',
    meta: {
      title: '业主管理',
      icon: 'el-icon-user'
    },
    children: [
      {
        path: 'master',
        component: () => import('@/views/village/owner/index'),
        name: '/owner/master',
        meta: { title: '业主信息', icon: 'el-icon-postcard' }
      },
      {
        path: 'homeCheck/:id',
        component: () => import('@/views/village/owner/page/homeCheck'),
        name: '/owner/homeCheck',
        meta: { title: '房屋入住', icon: 'el-icon-postcard' }
      },
      {
        path: 'ownerDetails/:id/:num',
        component: () => import('@/views/village/owner/page/ownerDetails'),
        name: '/owner/ownerDetails',
        meta: { title: '业主详情', icon: 'el-icon-postcard' }
      },
      {
        path: 'removeRoom/:id/:num',
        component: () => import('@/views/village/owner/page/ownerDetails'),
        name: '/owner/removeRoom',
        meta: { title: '房屋解绑', icon: 'el-icon-postcard' }
      },
      {
        path: 'member',
        component: () => import('@/views/village/familys/index'),
        name: '/owner/member',
        meta: { title: '业主成员', icon: 'el-icon-bangzhu' }
      }
    ]
  },
  {
    path: '/wisdom',
    component: Layout,
    redirect: '/wisdom/notice',
    name: '/wisdom',
    meta: {
      title: '智慧服务',
      icon: 'el-icon-star-off'
    },
    children: [
      {
        path: 'notice',
        component: () => import('@/views/smart/notice/noticeManage'),
        name: '/wisdom/notice',
        meta: { title: '公告管理', noCache: true ,icon: 'el-icon-star-off'}
      },
      {
        path: 'visitor',
        component: () => import('@/views/error-page/404'),
        name: '/wisdom/visitor',
        meta: { title: '访客登记', noCache: true ,icon: 'el-icon-bicycle'}
      },
      {
        path: 'complaint',
        component: () => import('@/views/error-page/404'),
        name: '/wisdom/complaint',
        meta: { title: '投诉意见', noCache: true ,icon: 'el-icon-chat-line-round'}
      },
      {
        path: 'investigation',
        component: () => import('@/views/error-page/404'),
        name: '/wisdom/investigation',
        meta: { title: '问卷调查', noCache: true ,icon: 'el-icon-edit-outline'}
      }
    ]
  },
  {
    path: '/repair',
    component: Layout,
    redirect: '/repair/register',
    name: '/repair',
    meta: {
      title: '报修管理',
      icon: 'el-icon-phone-outline'
    },
    children: [
      {
        path: 'register',
        component: () => import('@/views/error-page/404'),
        name: '/repair/register',
        meta: { title: '报修登记' ,icon: 'el-icon-document-checked'}
      },
      {
        path: 'dispatch',
        component: () => import('@/views/error-page/404'),
        name: '/repair/dispatch',
        meta: { title: '派单信息' ,icon: 'el-icon-brush'}
      },
      {
        path: 'report',
        component: () => import('@/views/error-page/404'),
        name: '/repair/report',
        meta: { title: '我的报修' ,icon: 'el-icon-files'}
      }
    ]
  },

  {
    path: '/cost',
    component: Layout,
    redirect: '/cost/charge',
    name: '/cost',
    meta: {
      title: '费用管理',
      icon: 'el-icon-notebook-1'
    },
    children: [
      {
        path: 'charge',
        component: () => import('@/views/error-page/404'),
        name: '/cost/charge',
        meta: { title: '房屋收费' ,icon: 'el-icon-bank-card'}
      },
      {
        path: 'arrears',
        component: () => import('@/views/error-page/404'),
        name: '/cost/arrears',
        meta: { title: '欠费清单' ,icon: 'el-icon-s-order'}
      },
      {
        path: 'bill',
        component: () => import('@/views/error-page/404'),
        name: '/cost/bill',
        meta: { title: '查看账单' ,icon: 'el-icon-reading'}
      }
    ]
  },

  {
    path: '/system',
    component: Layout,
    redirect: '/system/department',
    alwaysShow: true,
    name: '/system',
    meta: { title: '系统管理', icon: 'el-icon-setting' },
    children: [
      {
        path: 'department',
        component: () => import('@/views/system/organization/index'),
        name: '/system/department',
        meta: { title: '组织管理' ,icon: 'tree'}
      },
      {
        path: 'details/:id',
        component: () => import('@/views/system/organization/components/details'),
        // hidden: true // 是否显示在左侧菜单
        name: 'details',
        meta: {title: '详情'}
      },
      {
        path: 'user',
        component: () => import('@/views/error-page/404'),
        name: '/system/user',
        meta: { title: '员工信息' ,icon: 'el-icon-suitcase'}
      },
      {
        path: 'loginLog',
        component: () => import('@/views/system/loginLog/index'),
        name: '/system/loginLog',
        meta: { title: '登录日志' ,icon: 'el-icon-warning-outline'}
      },
      {
        path: 'log',
        component: () => import('@/views/system/operLog/index'),
        name: '/system/log',
        meta: { title: '操作日志' ,icon: 'el-icon-document'}
      },
      {
        path: 'news',
        component: () => import('@/views/profile/index'),
        name: '/system/news',
        meta: { title: '个人消息' ,icon: 'el-icon-user'}
      },
      {
        path: 'updatePwd',
        component: () => import('@/views/system/userPwd'),
        name: '/system/updatePwd',
        meta: { title: '修改密码' ,icon: 'el-icon-user'}
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]

export const LastRoutes = [

]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
